package com.elite.groovy.callback

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import com.elite.groovy.util.EliteBean

/**
 * 首拨呼损转预约
 * @author szwb2
 *
 */
class FirstCallLossTransferAppointment implements ServiceBackInvoke {
	private static final Log log=LogFactory.getLog(FirstCallLossTransferAppointment.class);

	@Override
    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {
			try {
				/*查询历史表当天推送类型为首拨且首拨推送成功的，
				 * 且其中没有录音的数据工单状态改为预约并且期望拨打时间为当前时间加一天*/
                String sql="update elitetask set expectstarttime = sysdate + 1, obstatus = 'OPEN',elitetaskstatus = 'OPEN' where customer_guid in (select c.customer_guid from List_Push_history l left join customer c on l.customer_guid = c.customer_guid left join customer c2 on c.parent_guid = c2.customer_guid left join event t on l.customer_guid = t.customer_guid where l.is_flag = '0' and l.send_type = '2' and (t.callestablished = '0' or t.customer_guid is null) and l.createddate >= trunc(sysdate) + 12 / 24 and l.createddate <= (TRUNC(SYSDATE) + 1 - 1 / 86400) and l.customer_guid not in(select l.customer_guid from List_Push_history l left join event t on l.customer_guid = t.customer_guid where l.is_flag = '0' and l.send_type = '2' and (t.callestablished = '1' or t.customer_guid is not null) and l.createddate >= trunc(sysdate) + 12 / 24 and l.createddate <= (TRUNC(SYSDATE) + 1 - 1 / 86400)))";
				int res = eliteBean.update(sql, "dataSource");
				log.debug("当日下午首拨呼损转为预约的数量:"+res);
				/*if(res>0) {
					 return "处理完成，首拨呼损转预约名单为：" +res;
				}else {
					 return "处理完成，未找到相应的首拨呼损名单：";
				}*/
			} catch (Exception e) {
				e.printStackTrace()
			}
					
	}
}
